package control;

import brain.SortManager;
import logger.Logger;
import managment.Manager;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import view.Runner;
import view.View;

/**
 * @author  Owner
 */
public class SortControl implements MouseListener {

    View view;

    public SortControl() {
	view = View.getInstance();
    }

    public void mouseDoubleClick(MouseEvent arg0) {
    }

    public void mouseDown(MouseEvent e) {
		if (!Runner.getInstance().getSimMode()) {
			Runner.getInstance().setPausePlayImg("pause.png");
			int selectedIndex = view.getSelectArrayIndex();
			if (selectedIndex == -1) {
				// error no selection.
				Logger.showWarningMessage(View.getInstance().getShell(), "           No Array is Selected            ");
			} else {

				SortManager sortManager = SortManager.getInstance();
				sortManager.manageSort(Manager.getInstance().getWorkArray(
						selectedIndex), view.getSimulationArray());
				view.setStatistics(sortManager.getStatisticsArray());
			}
		}
	}

    public void mouseUp(MouseEvent arg0) {
    }

}
